define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'adv/index' + location.search,
                    // add_url: 'shop/add',
                    // edit_url: 'shop/edit',
                    // del_url: 'shop/del',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                commonSearch: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                exportDataType: false,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('用户ID')},
                        {field: 'title', title: __('广告主题')},
                        {field: 'content', title: __('广告内容'),formatter: Table.api.formatter.content},
                        {field: 'images', title: __('广告图片'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'url', title: __('链接地址')},
                        {field: 'url_title', title: __('链接标题')},
                        {field: 'city', title: __('城市')},
                        {field: 'gender', title: __('性别')},
                        {field: 'age', title: __('年龄')},
                        {field: 'price', title: __('单价')},
                        {field: 'num', title: __('数量')},
                        {field: 'total', title: __('总价')},
                        {field: 'see_num', title: __('浏览人数')},
                        {field: 'status', title: __('审核状态'), searchList: {"0":__('待审核'),"1":__('发布中'),"2":__('已结束'),"3":__('已停止'),"4":__('驳回')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate_auth1',
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'auth1_pass',
                                    title: __('通过'),
                                    text: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    // icon: 'fa fa-check',
                                    confirm: '确认通过当前广告？',
                                    url: 'adv/auth_deal?type=1',
                                    success: function (data, ret) {
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                        $(".btn-refresh").trigger("click");
                                    },

                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'auth1_no',
                                    title: __('拒绝'),
                                    text: __('驳回'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    // icon: 'fa fa-times',
                                    confirm: '确认拒绝当前广告？',
                                    url: 'adv/auth_deal?type=4',
                                    success: function (data, ret) {
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        cash: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});